package com.hmall.controller;

import com.hdmall.business.common.annotation.LoginRequired;
import com.hdmall.business.common.common.ServerResponse;
import com.hmall.model.SysUser;
import com.hmall.service.OrderService;
import com.hmall.util.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.JedisPool;

/**
 * @ClassName OrderController
 * @Description
 * @Author zhoutao
 * @Date 2018/12/5 15:04
 * @Version 2.0
 **/
@RestController
@Api(value = "订单接口", description = "订单API说明")
@RequestMapping(value = "/order/")
public class OrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    JedisPool jedisPool;

    TokenUtil tokenUtil = new TokenUtil();
    @LoginRequired
    @GetMapping("listHistoryProduct")
    @ApiOperation(value = "列出历史订单产品列表", notes = "订单状态发货之后都算")
    public ServerResponse historyProductList(String token, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return orderService.listHistoryProduct(user.getUserId(), pageNum, pageSize);
    }
    @LoginRequired
    @PostMapping("createOrderByHistory")
    @ApiOperation(value = "通过历史产品列表下订单")
    public ServerResponse createOrderByHistory(String token, Integer customerUserId, String productPlanOrderJsonStr,Integer shippingId, Integer distCode, String remark, Integer transportId) throws Exception {


        SysUser user =tokenUtil.tokenToUser(jedisPool, token).getData();
         return orderService.createOrderHistory(token, user.getUserId(), productPlanOrderJsonStr, shippingId, distCode, remark, transportId, "history");
    }


}
